local string_plit =  function (szFullString, szSeparator)
	local nFindStartIndex = 1
	local nSplitIndex = 1
	local nSplitArray = {}
	while true do  
	   local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)  
	   if not nFindLastIndex then  
	    nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))  
	    break
	   end
	   nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)  
	   nFindStartIndex = nFindLastIndex + string.len(szSeparator)  
	   nSplitIndex = nSplitIndex + 1  
	end
	return nSplitArray
end

local get_fields_by_userid = function (key, userid)
  local bulk = redis.call('HGETALL', key)
  local result = {}
  local nextkey
  for i, v in ipairs(bulk) do
  	local field_arr = string_plit(v, '.')
  	if table.getn(field_arr) > 0 then
  		if field_arr[1]==userid then
  			table.insert(result, v)
  		end
	end
	return result
end

local cache_key = KEYS[1]
local userid = KEYS[2]
return get_fields_by_userid(cache_key, userid)
end